< previous page page_53 next page >

Page 53
0053-01.jpg
Figure 3.4.
Display RecordCount
of the Filtered Recordset.
It is also important to notice that the second Recordset object was created from the first Recordset object. This a very powerful feature of Visual Basic. When you want to get a smaller dataset, you don't have to reload the data from the database; you can use an existing Recordset as the source for a new dataset.
Tip.gif
Creating subsets of a Recordset in this manner can sometimes be slower than simply creating a new Recordset from the database itself. The exception to this rule is when your database is stored at a distant server. In cases where your source data is far away and possibly available only over a slow network connection, using the Filter property to create subsets of data can be faster.

Now let's make one more series of changes to DYNASETS.VBP that illustrate the Clone method for Recordsets. Cloning a Recordset makes a duplicate of the set. Add another data object (rs3), and add the Clone Recordset program code in Listing 3.8.
Type.gifListing 3.8. Cloning a new Recordset.
Private Sub Form_Load()
    '
    ' creating dynaset-type recordsets
    '
    Dim db As Database ' the database object
    Dim rs As Recordset ' the recordset object
    Dim rs2 As Recordset ' another recordset
    Dim rs3 As Recordset ' for cloning
    '
    ' create local variables
    Dim strDBName As String
    Dim strRSName As String
    Dim intRecs As Integer
    Dim strFilter As String
    '
    ' initialize the variables
    strDBName = App.Path & "\..\data\books5.mdb"
    strRSName = "Titles"
    strFilter = "YearPub>1990"
    '
continues

 
< previous page page_53 next page >

If you like this book, buy it!